define(function(require, exports, module){
	var cloudprocurementTemp = require("text!../template/MDM.html");
	//var Scroll = require("scroll");
	
	module.exports = Nuui.View.extend({

		template:cloudprocurementTemp,

		onRender:function(){
			var view=this;
			
		},

		onShow:function(){            
			var view = this;
			var cate=App.storage.get('productCode');
			var target=App.storage.get('yunCode');

			App.request(App.server.getServePath(App.path.productAction),{
				success:function(data){
					if(data.ec){
						alert(data.em);
						
					}else{		

						var res = data.productList[target];
						var tagLists=res.productClassification;
						var intro=res.introduce.detailedIntroduction;
						if(target=="tracingEvidence"){
							view.$('.info .part-mid .unit').html('元/次');
							view.$('.info .part-mid .buyNum').addClass('active');
							view.$('.page .info .part-bottom .tips').addClass('active');
							
				
							view.$('.info .part-mid .buyNum .addNum').on('tap',function(){
								var currNum=view.$('.info .part-mid .buyNum .nums').text().trim();
								currNum++;
								view.$('.info .part-mid .buyNum .nums').text(currNum);
							})
							view.$('.info .part-mid .buyNum .reduceNum').on('tap',function(){
								var currNum=view.$('.info .part-mid .buyNum .nums').text().trim();
								
								if(currNum<=1){return;}
								currNum--;
								view.$('.info .part-mid .buyNum .nums').text(currNum--);
							})
						
						
						}
						if(intro){
							if(intro.length>150){
								intro=intro.slice(0,150);
								intro+="..."
							}
							view.$(".descrip .tab-content .description").html(intro);
						}
						
						if(res.name_CN){
							view.$(".info .part-top .title").html(res.name_CN);
						}else{
							alert(res.name_CN+"is empty");
						}
						
						if(res.sales){
							view.$(".info .part-mid .sales").html(res.sales);
						}else{
							alert(res.sales+"is empty");
						}
						
						if(res.detailImg){
							view.$(".banner").css({"background":"url(../../../images/img/"+res.detailImg+") no-repeat center","background-size":"100%"});
						}else if(res.logo){
							view.$(".banner").css({"background":"url(../../../images/img/"+res.listImg+") no-repeat center","background-size":"100%"});
						}else{
							alert(res.logo+"is empty");
						}		
						view.$(".operation .shop").attr("data-shop",res.shopLink);
						view.$(".operation .shop").on('tap',function(){
							sessionStorage.setItem("key", res.shopLink)
			                App.navigate("example/index/productService", true);
			                return false;
						})
						
						
						/*if(res.introduce.commet){
							view.$(".descrip .tab-content .comment").html(res.introduce.commet);
						}else{
							view.$(".descrip .tab-content .comment").css({
								"background":"url(../../../images/img/nocommet.png) no-repeat center",
								"background-size":"50%"
							});
						}*/
						
						for(var i=0;i<tagLists.length;i++){
							var html='';
							html+='<label class="tag">'+tagLists[i]+'</label>';
							view.$('.info .part-bottom').prepend(html);
						}
						
					}
				}
			})
			/*介绍、评论*/
			view.$('.descrip .tab-item').on('tap',function(){
				if($(this).hasClass('description')){					
				view.$('.tab-content .description').addClass('active').siblings().removeClass('active');
				view.$('.descrip .tab-item.description').addClass('active').siblings().removeClass('active');					
				}else{
					view.$('.tab-content .comment').addClass('active').siblings().removeClass('active');
					view.$('.descrip .tab-item.comment').addClass('active').siblings().removeClass('active');
				}

			})
			/*收藏*/
			view.$('.info .collect').on('tap',function(){
				if($(this).hasClass('active')){
					Nuui.utils.toast("取消收藏",{'title':''});
					$(this).removeClass('active');
				}else{
					Nuui.utils.toast("收藏成功",{'title':''});
					$(this).addClass('active');
				}
				return false;
			})
			/*头部返回显示*/
			var backTitle=App.storage.get("productName");
			$('.header_btn_left').html("<span class='iconfont icon-leftarrow'>"+backTitle+"</span>");
			//$('.header_btn_left').append(backTitle);
			/*立即购买*/
			view.$('.operation .buy').on('tap',function(){
				App.navigate('example/index/payMethod',true);
				return false;
			})

		}
	});
});